package com.daiqile.rxjava;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.eftimoff.patternview.PatternView;

public class LockActivity extends AppCompatActivity {
    private PatternView patternView;

    private String patternString;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lock);
         patternView = (PatternView) findViewById(R.id.patternView);
        patternView.setTactileFeedbackEnabled(false);
        Toast.makeText(getApplicationContext(), "输入手势", Toast.LENGTH_LONG).show();
        patternView.setOnPatternDetectedListener(new PatternView.OnPatternDetectedListener() {

            @Override
            public void onPatternDetected() {
                if (patternString == null) {
                    patternString = patternView.getPatternString();
                    patternView.clearPattern();
                    Toast.makeText(getApplicationContext(), "请再次输入", Toast.LENGTH_SHORT).show();

                    return;
                }
                if (patternString.equals(patternView.getPatternString())) {
//                    Toast.makeText(getApplicationContext(), "手势密码正确", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(LockActivity.this,MainActivity.class);
                    startActivity(intent);
                    return;
                }
                    patternView.clearPattern();
                    Toast.makeText(getApplicationContext(), "手势密码错误", Toast.LENGTH_SHORT).show();
                       patternView.disableInput();//锁定
                }
        });
    }
}